<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2014.07.28.
   家居商家作品控制器($$)*/

!defined('Q_PATH') && exit;

class JiajucaseController extends AController{

	public function filter_(&$arrMap){
		$arrMap['A.jiajucase_title']=array('like',"%".Q::G('jiajucase_title')."%");
		$arrMap['A.jiajucase_picnum']=array('egt',intval(Q::G('jiajucase_picnum')));
		$arrMap['A.jiajucase_viewnum']=array('egt',intval(Q::G('jiajucase_viewnum')));
		$arrMap['A.jiajucase_realprice']=array('egt',intval(Q::G('jiajucase_realprice')));
		$arrMap['A.jiajucase_realspace']=array('egt',intval(Q::G('jiajucase_realspace')));

		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);

		// 待审
		$this->getAudit_('A.jiajucase_status',$arrMap);
	}

	public function index($sModel=null,$bDisplay=true){
		parent::index('jiajucase',false);
		$this->display(Admin_Extend::template('jiaju','jiajucase/index'));
	}

	protected function sqljoin_(){
		return "->join('".Q::C('DB_PREFIX')."jiajucompany AS C','C.jiajucompany_id,C.jiajucompany_fullname,C.jiajucompany_isfvip,C.jiajucompany_domain','A.jiajucompany_id=C.jiajucompany_id')";
	}

	public function add(){
		$this->bAdd_();
		$this->display(Admin_Extend::template('jiaju','jiajucase/add'));
	}

	public function bAdd_(){
		// 作品属性
		$oJiajucompanyclass=Q::instance('JiajucompanyclassModel');
		$this->assign('arrStyleclass',$oJiajucompanyclass->getClass(52));
		$this->assign('arrSpaceclass',$oJiajucompanyclass->getClass(53));
		$this->assign('arrPriceclass',$oJiajucompanyclass->getClass(50));
		$this->assign('arrAreaclass',$oJiajucompanyclass->getClass(51));
	}

	public function edit($sMode=null,$nId=null,$bDidplay=true){
		$nId=intval(Q::G('value','G'));
		$this->bEdit_();
		parent::edit('jiajucase',$nId,false);

		// 服务区域和类型
		$oJiajucompany=Q::instance('JiajucompanyModel');
		$this->assign('arrBusinessclass_',$oJiajucompany->getClass($nId,'jiajucompanybusinessclass'));
		$this->assign('arrDistrict_',$oJiajucompany->getClass($nId,'jiajucompanydistrict'));
		$this->assign('arrHomeclass_',$oJiajucompany->getClass($nId,'jiajucompanyhomeclass'));
		$this->assign('arrStyleclass_',$oJiajucompany->getClass($nId,'jiajucompanystyleclass'));

		$this->display(Admin_Extend::template('jiaju','jiajucase/add'));
	}

	public function bEdit_(){
		$nId=intval(Q::G('value','G'));
		// 作品内容
		$sContent=JiajucasecontentModel::F('jiajucase_id=?',$nId)->getColumn('jiajucase_content');
		$this->assign('sContent',$sContent);

		$this->bAdd_();
	}

	public function get_designer(){
		$nCpId=intval(Q::G('cp_id','G'));
		$nDesignerId=intval(Q::G('designer_id','G'));
		if(!$nCpId){
			exit('<span style="color:red;">你没有选择任何商家</span>');
		}

		$arrDesigners=Model::F_('jiajudesigner')->where(array('jiajucompany_id'=>$nCpId,'jiajudesigner_status'=>1))
			->setColumns('jiajudesigner_id,jiajudesigner_name')
			->order('jiajudesigner_id DESC')
			->getAll();

		echo '<select name="jiajudesigner_id" id="jiajudesigner_id" class="">
				<option value="">- 请选择 -</option>';
		foreach($arrDesigners as $arrDesigner){
			echo "<option value=\"{$arrDesigner['jiajudesigner_id']}\" ".($nDesignerId==$arrDesigner['jiajudesigner_id']?'selected':'').">{$arrDesigner['jiajudesigner_name']}</option>";
		}
		echo '</select>';
	}

	public function insert($sModel=null,$nId=null){
		$oJiajucase=new JiajucaseModel();
		$oJiajucase->saveData(intval(Q::G('jiajucompany_id')));
		if($oJiajucase->isError()){
			$this->E($oJiajucase->getErrorMessage());
		}

		$this->A($oJiajucase->toArray(),'作品添加成功',1);
	}

	public function update($sModel=null,$nId=null){
		$nId=intval(Q::G('value'));

		$oJiajucase=JiajucaseModel::F('jiajucase_id=?',$nId)->getOne();
		$oJiajucase->updateData(intval(Q::G('jiajucompany_id')));
		if($oJiajucase->isError()){
			$this->E($oJiajucase->getErrorMessage());
		}

		$this->S('作品更新成功');
	}

	public function forbid($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::forbid('jiajucase',$nId,true);
	}

	public function resume($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::resume('jiajucase',$nId,true);
	}

	public function clear_recycle($sModel=null,$sField='status'){
		parent::clear_recycle('jiajucase',$sField);
	}

	public function foreverdelete_deep($sModel=null,$sId=null){
		$sId=Q::G('value');
		parent::foreverdelete_deep('jiajucase',$sId);
	}

	public function foreverdelete($sModel=null,$sId=null,$bApp=false){
		$sId=Q::G('value');
		parent::foreverdelete('jiajucase',$sId,true);
	}

	public function view_preview($sMode=null,$nId=null,$bDidplay=true){
		$nId=intval(Q::G('value','G'));
		
		// 作品内容
		$sContent=JiajucasecontentModel::F('jiajucase_id=?',$nId)->getColumn('jiajucase_content');
		$this->assign('sContent',$sContent);

		parent::view_preview('jiajucase',$nId,false);
		$this->display(Admin_Extend::template('jiaju','jiajucase/viewpreview'));
	}

	public function save_preview($sMode=null,$nId=null){
		$nId=intval(Q::G('value','G'));
		parent::save_preview('jiajucase',$nId);
	}

	public function save_previewstatus($sMode=null,$nId=null){
		$nId=intval(Q::G('value','G'));
		parent::save_previewstatus('jiajucase',$nId);
	}

}
